package com.pengtu.entity.app;

import java.util.Comparator;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.pengtu.entity.IdEntity;

@Entity
@Table(name = "T_APP_WORKLOG")
public class WorkLog extends IdEntity {

	/**
	 * serialVersionUID:TODO
	 * 
	 * @since 1.0.0
	 */

	private static final long serialVersionUID = 1L;

	private String task;
	private String content;
	private Date workDate;
	private Integer spendTime;
	private Double schedule;
	private String type;
	private String owner;
	private String remark;
	private Set<Attachment> attachmentSet = new TreeSet<Attachment>(
			new Comparator<Attachment>() {
				@Override
				public int compare(Attachment attFirst, Attachment attSecond) {
					// TODO Auto-generated method stub
					return attFirst.getCreateDate().compareTo(
							attSecond.getCreateDate());
				}
			}); // 附件

	@Column(name="TASK")
	public String getTask() {
		return task;
	}

	public void setTask(String task) {
		this.task = task;
	}

	@Column(name="CONTENT")
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name="WORKDATE")
	@Temporal(TemporalType.DATE)
	public Date getWorkDate() {
		return workDate;
	}

	public void setWorkDate(Date workDate) {
		this.workDate = workDate;
	}

	@Column(name="SPENDTIME")
	public Integer getSpendTime() {
		return spendTime;
	}

	public void setSpendTime(Integer spendTime) {
		this.spendTime = spendTime;
	}

	@Column(name="SCHEDULE")
	public Double getSchedule() {
		return schedule;
	}

	public void setSchedule(Double schedule) {
		this.schedule = schedule;
	}

	@Column(name="TYPE")
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	@Column(name="OWNER")
	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}
	
	@Column(name="REMARK")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "TABLEID")
	public Set<Attachment> getAttachmentSet() {
		return attachmentSet;
	}

	public void setAttachmentSet(Set<Attachment> attachmentSet) {

		this.attachmentSet = attachmentSet;
	}

	@Transient
	public Attachment getAttachment() {
		if (attachmentSet.iterator().hasNext())
			return attachmentSet.iterator().next();
		return new Attachment();
	}

	public void setAttachment(Attachment attachment) {
		attachmentSet.clear();
		attachmentSet.add(attachment);
	}
}
